<?php
define('IN_PHPBB', true);
$phpbb_root_path = './forum/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

// not used anymore

class University {
	public $Name;
	public $Address;
}
class School {
	public $Name;
	public $Address;
}
class Employer {
	public $Name;
	public $Address;
}
class UserInSchool {
	public $User_id;
	public $SchoolName;
}
class UserInUniversity {
	public $User_id;
	public $UniversityName;
	public $Grade;
	public $Department;
	public $Concentration;
	public $DateIn;
	public $DateOut;
}
class UserInCompany {
	public $User_id;
	public $CompanyName;
	public $Position;
	public $Department;
	public $Address;
	public $DateIn;
	public $DateOut;
}

class Address {
	public $Street;
	public $City;
	public $State;
	public $Country;
	public $ZIP;
	public $Website;
	
}
	
$GLOBALS['user'] = $user;
class cMyPage {

	function friendStatus($fid) {
		global $db, $user; 
		$sql = "SELECT status FROM Friends WHERE User1_id = '$fid' AND user2_id = '".$user->data['user_id']."' OR `user2_id` = '$fid' AND `User1_id` = '".$user->data['user_id']."'";
		$q = $db->sql_query($sql);
		$count = $db->sql_affectedrows();
		if($count == 0)
			return "NO";
		else {
			$row = $db->sql_fetchrow($q);
			return $row['status'];
		}
	}
	
	function isLoggedIn() {
	global $user;
	if( $user->data['is_registered'] ) {
		return true;
	}
	else {
		return false;
	}
}
// TODO
function isAdmin() {
	
}
function isRPI() {
	global $user;
	$test = "rpi.edu";
	$str = substr($user->data['user_email'], strlen($user->data['user_email'])-7, strlen($user->data['user_email']));
		if( strcmp($str, $test) == 0) 
			return true;
				
	return false;
}
// TODO check 
function isFriend($f1,$f2) {
	global $db;
//made to check any 2 people for friends relationship - for 2.0
	$friend_sql="SELECT u.username, u.user_id, f.status FROM phpbb_users u, friends f WHERE ((f.user1_id=" . $f1 . " AND f.user2_id=". $f2 . " AND f.user1_id=u.user_id) OR (f.user2_id=" . $f1." AND f.user1_id=".$f2." AND f.user2_id=u.user_id)) ORDER BY f.status, u.username";
    $friend_row=$db->sql_query($friend_sql);
	 $row = $db->sql_fetchrow($friend_row);
	if ($row['user_id']!=NULL) 
	{
		return true;
	}
	return false;
}

function loadHeader() { global $user; ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>RPI iConnect</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<link rel="stylesheet" href="css/template.css" type="text/css" />
<link rel="Shortcut Icon" href="rpi.ico" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/functions.js"></script>
<script src="js/jquery.MultiFile.js" type="text/javascript" language="javascript"></script>

		
</head>
<body>
<div id="masthead">
  <div id="redBorder"></div>
	<h1 id="siteName"><a href="/" title="ITWS@RPI"><img src="/images/earth-5.png" alt="" width="130" height="115" border="0" /> </a>  RPI Students Social Network </h1>
    <div id="utility"> 
  	<?php
	if($this->isLoggedIn())	 { 
	    echo '<a id="logoutLink" href="#">Log Out </a>';
	}
	else {
		echo '<p><a href="register.php">Register</a> | 
 <a href="profile.php">Log In</a></p>';
	}
	?>    
	</p>
	    
    <p>
    <?php

    if($this->isLoggedIn())
    {
        //User is logged into phpBB, welcome user and display whether there is new message
	   echo "Welcome back, ".$user->data['username']."."."<br />"."<br />";
	   echo "You have ".'<a href="/forum/ucp.php?i=pm&amp;folder=inbox">'.$user->data['user_new_privmsg'].'</a> '." new message(s)";
	   
    }
    else
    {
         //User is not logged into phpBB
	    echo "Welcome Guest";
    }
    ?>
    
    
    </p>
  </div>

  <div id="globalNav"> <img alt="" src="/images/gblnav_left.gif" height="32" width="4" id="gnl" /> <img alt="" src="images/glbnav_right.gif" height="32" width="4" id="gnr" />
    <div id="globalLink"> 
    <a href="/index.php" id="gl1" class="glink"> News </a>    

    <a href="userinfo.php" id="gl2" class="glink" > My Page </a>
    <a href="profile.php" id="gl3" class="glink" > Edit Profile </a>

    <a href="members.php" id="gl4" class="glink"> Members </a>
    <a href="/forum" id="gl5" class="glink" > Forum </a>
    </div>
    <!--end globalLinks-->
    <form id="search" name="search" action="search.php" method="post">
      <input name="searchFor" type="text" size="21" />
      <a href="#" onclick="javascript:searchsubmit()">search</a>
    </form>
    <script type="text/javascript">
	 function searchsubmit() {
	 document.search.submit();
	 }
	 </script>
  </div>
  <!-- end globalNav -->
<?php
} //function

function loadFooter() { ?>
</div>
</div> 
   <div id="siteInfo"><a href="#">Site Map</a> | <a href="#">Privacy Policy</a> | <a href="#">Copyright Notice</a> | <a href="#">Your Feedback</a> | <a href="#">Contact Us</a> | <a href="#">Search</a></div> 
   <div id="copyRight">Copyright &copy; 2010, iConnect Team </div>
   <div id="bottomInfo">This is NOT RPI ITWS or CS official website!!! <br /> This website is built by iConnect Team and managed by ITWS Student Leadership Committees. <br />We want to provide an online communication platform for current students, future students and alumni. And we wish you have fun here! </div>

   <div id="redBorder"></div>
</div>

<!--end pagecell1-->	
</body>
</html>
<?php } //function loadFooter()
function loadTitle($title) {  ?>
<div id="pagecell1">
  <!--pagecell1-->

  <div id="pageName">
    <h2><? echo $title; ?></h2>
  </div>
<?php
} //function loadTitle()
function loadLocation($locArray) { ?>
<div id="location"> &nbsp; &nbsp; Your Location:  
<? 
foreach($locArray as $l) {
	echo '<a href="'.$l['url'].'">  '.$l['name'].' </a> ';
	if(end($locArray) != $l) 
		echo '>';
}
} //function loadLocation()
function loadLinks() { ?>
    <div id="pageNav">
    <div id="sectionLinks"> <a href="/index.php">NEWS!!</a> <a href="ITWS.php">ITWS@RPI</a> <a href="undergraduate.php">Undergraduate Degree</a> <a href="graduate.php">Graduate Degree</a> <a href="faculty.php">Faculty</a> <a href="alumni.php">Alumni</a> </div>
    <div class="relatedLinks">
      <h3>FAQs </h3>
      <a href="about_RPI.php">About RPI </a> <a href="about_Troy.php">About Troy </a> <a href="scholarship">  Scholarship </a> <a href="tuition.php">Tuition Fee </a> <a href="housing.php">Housing</a> <a href="career.php">Career</a> </div>
    <? /*?><div class="relatedLinks">
      <h3>Related Link Category</h3>
      <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> <a href="#">Related Link</a> </div><?php */?>
  </div>
  <?php
} // function loadLinks()
function loadPreContent($title) { ?>
<div id="content">
    <div class="content1">
      <h3><? echo $title; ?> </h3>
<?php
} //loadPreContent()
function loadPostContent() { ?>

  <?php
} //function loadPostContent()
function displayLogin() { ?>
<div id="divLogin">
<form name="login" onSubmit="loginForm()">
<table>
<tbody>
<tr><td>Username</td><td><input id="user" type="text" /></td></tr>
<tr><td>Password</td><td><input id="pass" type="password" /></td></tr>
<tr><td align="center" colspan="2">
<input type="button" value="Login" id="loginForm" class="btn" /> or 
 <a href="register.php">Register</a></td></tr>
</tbody>
</table>
</form>
<div id="divLoginAlert"></div>
</div>
<?php }
} // class ?>